package com.echo.ssm.service;

import java.util.List;
import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.echo.ssm.mapper.BkResourceMapper;
import com.echo.ssm.mapper.BkRoleMapper;
import com.echo.ssm.mapper.BkUserMapper;
import com.echo.ssm.mapper.BkUserRoleMapper;
import com.echo.ssm.model.BkResource;
import com.echo.ssm.model.BkRole;
import com.echo.ssm.model.BkUser;
import com.echo.ssm.model.BkUserRole;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

/**
 * 后台用户权限管理模块
 * @author tangsixiang
 *
 */
@Service
public class PowerMangerService {
   
   @Resource
   private  BkResourceMapper resourceMapper;
   @Resource
   private  BkRoleMapper   bkRoleMapper;
   @Resource
   private  BkUserMapper bkUserMapper;
   @Resource
   private  BkResourceMapper bkResourceMapper;
   @Resource
   private  BkUserRoleMapper  bkUserRoleMapper ;
   
   
   public  int   addUse(BkUser  user){
	     if(user.getUserId()==null){
	    	 user.setUserId(UUID.randomUUID().toString().replaceAll("-",""));
	     }
	   return bkUserMapper.insertSelective(user);
   }
   public Page<BkUser>  selectkUser(Integer pageSize,Integer pageNum){
	     Page<BkUser> pages = PageHelper.startPage(pageNum, pageSize);
	       bkUserMapper.selectByList();
	     return    pages;
   } 
   public  BkUser   selectById(String   userId){
	   return bkUserMapper.selectByPrimaryKey(userId);
   }
   
   public  int    updateUser(BkUser   user){
	   return bkUserMapper.updateByPrimaryKeySelective(user);
   }
   public  int    deleteUser(String   userId){
	   //删除角色和用户中间表的次用户的数据
	   return bkUserMapper.deleteByPrimaryKey(userId);
   }
   
   
   /**
    * 添加角色
    * @param role
    * @return
    */
   public  int   addRole(BkRole  role){
	   return bkRoleMapper.insertSelective(role);
   }

   public  int   addResouce(BkResource  resource){
	   return bkResourceMapper.insertSelective(resource);
   } 
   
   public  int    deleteUserRole(String   userId){
	   //删除角色和用户中间表的次用户的数据
	   return bkUserRoleMapper.deleteUserRole(userId);
   }
   
  public  List<BkRole>  selectRole(){
	   
	   return bkRoleMapper.selectList();
   } 
   public  int  addBkUserRole(BkUserRole  userRole){
	   return bkUserRoleMapper.insertSelective(userRole);
   } 
}
